package com.kfm.wiki.job;

import cn.hutool.core.util.IdUtil;
import com.kfm.wiki.service.DocService;
import com.kfm.wiki.service.EbookSnapshotService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
@Slf4j
public class EbookSnapshotJob {

    @Autowired
    private EbookSnapshotService ebookSnapshotService;

//    @Scheduled(cron = "0 0 0/1 * * ?")
    @Scheduled(fixedRate = 1, timeUnit = TimeUnit.HOURS)
    public void updateCount(){
        // 增加日志流水号
        MDC.put("LOG_ID", String.valueOf(IdUtil.getSnowflakeNextId()));

        long start = System.currentTimeMillis();
        log.info("开始生成电子书快照");
        ebookSnapshotService.generatorSnapshot();
        log.info("电子书快照生成成功, 耗时：{}", System.currentTimeMillis() - start);
    }
}
